from utils.network import Interface
from utils import memory
from utils.model import User


class API(Interface):
    def handle(self, req):
        assert isinstance(req['account'], str) and req['account'] not in memory.users
        user = User(req['account'], req['password'], req['username'])
        memory.users[req['account']] = user
        return self.success_respond({
            'account': user.account,
            'username': user.username
        })
